package com.kabao.oms.controller;

import java.util.List;
import java.util.UUID;

import javax.smartcardio.Card;

import com.jfinal.aop.Before;
import com.jfinal.core.ActionKey;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.tx.Tx;
import com.kabao.oms.model.Cards;
import com.kabao.oms.service.kbyxService;
import com.kabao.oms.util.Message;

public class OMSOrder extends Controller{
	
	
//	@Before(Tx.class)
	public void index(){
		String uuid = UUID.randomUUID().toString().replace("-", "");
		System.out.println(uuid+"--------------");
		new Cards().set("id", uuid).set("cardm", "11111111").save();
		render("test.jsp");
	}
	
	public void getOrder(){
		System.out.println("------------------");
		String begin = getPara("page");
		String size = getPara("size");
		if(begin == null || size == null){
			begin = "0";
			size = "3";
		}
		
		String begincount = String.valueOf((Integer.valueOf(begin)-1)*Integer.valueOf(size));
		
		System.out.println(begin+"))))"+size);
		List<Cards> list = Cards.dao.find("select * from t_card_info limit "+begincount+","+size+"");
		System.out.println(list.size()+"$$$$$$$$$$$$$4");
		renderJson(list);
	}
	
	public void getTotal(){
		System.out.println("%%%%%%%%%%%%%%%%%%%");
		List<Cards> list = Cards.dao.find("select * from t_card_info");
		System.out.println(list.size());
		renderText(String.valueOf(list.size()));
	}
	
	public void insertRow(){
		String uuid = UUID.randomUUID().toString().replace("-", "");
//		new Cards().set("id", uuid).set("cardm", "11111111").save();
		renderText("1");
	}
	
	public void saveOrder(){
		String id = getPara("cardid");
		String cardm = getPara("cardm");
		System.out.println(cardm+"^^^^^^^^^^^^^^^^^^^");
		Cards.dao.findById(id).set("cardm", cardm).update();
		Message msg = new Message("保存成功","success","通知");
		renderJson(msg);
	}
	
	public void updateRow(){
		String id = getPara(0);
		Cards cards = Cards.dao.findById(id);
		renderJson(cards);
	}
	
	public void batchWork(){
		kbyxService service = new kbyxService();
		Message msg = null;
		String beginDate = "2015-04-01 09:08:00";//getCurrentDateTime();//计划开始时间
		String endDate = "2015-04-27 10:08:00";//计划结束时间
		try {
//			service.receiveOption(beginDate, endDate);
			service.receiveItemsOpt();
			msg = new Message("任务执行成功","success","通知");
		} catch (Exception e) {
			e.printStackTrace();
			msg = new Message("任务执行失败","info","通知");
		}
		
		renderJson(msg);
		
	}

}
